<template>
  <div>
    <el-table :data="skuList" style="width: 100%">
      <el-table-column type="index" label="序号" width="80"> </el-table-column>
      <el-table-column header-align="center" align="center" prop="skuName" label="名称" width="80">
      </el-table-column>
      <el-table-column header-align="center" align="center" prop="skuDesc" label="描述" width="80">
      </el-table-column>
      <el-table-column header-align="center" align="center" label="默认图片" width="width">
        <template slot-scope="{ row, $index }">
          <img :src="row.skuDefaultImg" style="height: 60px" alt="" />
        </template>
      </el-table-column>
      <el-table-column header-align="center" align="center" prop="weight" label="重量(kg)" width="110">
      </el-table-column>
      <el-table-column header-align="center" align="center" prop="price" label="价格" width="width">
      </el-table-column>
      <el-table-column header-align="center" align="center" prop="prop" label="操作" width="width">
        <template slot-scope="{ row, $index }">
          <el-button v-if="row.isSale == 1" type="success" icon="el-icon-top" circle @click="cancleSale(row)">
          </el-button>
          <el-button v-else type="success" icon="el-icon-bottom" circle @click="changeSale(row)"></el-button>
          <el-button type="info" icon="el-icon-message" circle @click="eidt()"></el-button>
          <el-button type="warning" icon="el-icon-star-off" circle @click="getSkuInfo(row)"></el-button>
          <el-button type="danger" icon="el-icon-delete" circle @click="deleteSku(row)"></el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 @size-change="handleSizeChange"
      @current-change="handleCurrentChange"-->
    <el-pagination @current-change="getSkuData" @size-change="handleSizeChange" style="text-align: center"
      :current-page="page" :page-sizes="[3, 5, 7, 9]" :page-size="limit"
      layout="prev, pager, next, jumper,->,total,sizes" :total="total">
    </el-pagination>
    <el-drawer :visible.sync="drawer" :with-header="false" :show-close="false" size=50%>
      <el-row>
        <el-col :span="6">名称</el-col>
        <el-col :span="18"> {{ skuInfo.skuName }}</el-col>
      </el-row>
      <el-row>
        <el-col :span="6">描述</el-col>
        <el-col :span="18"> {{ skuInfo.skuDesc }}</el-col>
      </el-row>
      <el-row>
        <el-col :span="6">价格</el-col>
        <el-col :span="18"> {{ skuInfo.price }}</el-col>
      </el-row>
      <el-row>
        <el-col :span="6">平台属性</el-col>
        <el-col :span="18">
          <template>
            <el-tag type="info" style="margin:0 10px" v-for="i in skuInfo.skuAttrValueList" :key="i.id">{{ i.attrName }}
            </el-tag>
          </template>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">商品图片</el-col>
        <el-col :span="18" style="margin-button:1px">
          <template>
            <div class="block">
              <el-carousel >
                <el-carousel-item v-for="item in skuInfo.skuImageList" :key="item.id">
                  <h3 class="small">
                    <img :src="item.imgUrl" alt="" style="width:100%;height:100%">
                  </h3>
                </el-carousel-item>
              </el-carousel>
            </div>
          </template>
        </el-col>
      </el-row>
    </el-drawer>
  </div>
</template>

<script>
export default {
  name: "Sku",
  data() {
    return {
      page: 1,
      limit: 3,
      skuList: [],
      total: 10,
      skuInfo: [],
      drawer: false,
    };
  },
  mounted() {
    this.getSkuData();
  },
  methods: {
    async getSkuData(pager) {
      this.page = pager || 1
      const { page, limit } = this;
      let result = await this.$API.sku.reqSku(page, limit);
      console.log(111, result);
      if (result.code == 200) {
        this.total = result.data.total
        this.skuList = result.data.records;
      }
    },
    handleSizeChange(limit) {
      this.limit = limit
      this.getSkuData()
    },
    async changeSale(row) {
      let result = await this.$API.sku.reSale(row.id)
      if (result.code == 200) {
        row.isSale = 1
        this.$message({ type: 'success', message: "上架成功" })
      }
    },
    async cancleSale(row) {
      let result = await this.$API.sku.reCancel(row.id)
      if (result.code == 200) {
        row.isSale = 0
        this.$message("下架成功")
      }
    },
    eidt() {
      this.$message('正在开发中')
    },
    async getSkuInfo(row) {
      let result = await this.$API.sku.reqSkuById(row.id)
      console.log(result);
      if (result.code == 200) {
        this.drawer = true
        this.skuInfo = result.data
      }

    },
    deleteSku(row){
     this.$message({type:'success',message:'删除成功'})
    }
  },
};
</script>

<style>

.el-drawer__header{
  margin-top: 10px;
}

.el-row {
  margin: 30px 0;
}

.el-col-6 {
  text-align: center;
}
.el-carousel__item,.el-carousel__container{
  width: 300px;
  height: 300px;
}
.el-carousel__item h3 {
    color: #475669;
    font-size: 14px;
    opacity: 0.75;
    line-height: 150px;
    margin: 0;
  }

  .el-carousel__item:nth-child(2n) {
     background-color: #99a9bf;
  }
  
  .el-carousel__item:nth-child(2n+1) {
     background-color: #d3dce6;
  }
</style>